package com.hoshiibuy.company.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hoshiibuy.common.rpc.Response;
import com.hoshiibuy.company.service.ICompanyService;
import com.hoshiibuy.company.entity.Company;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 公司 前端控制器
 * </p>
 *
 * @author WGJ
 * @since 2019-04-22
 */
@RestController
@RequestMapping("/company")
@Api(value = "公司管理", tags = {"公司操作接口"})
public class CompanyController {
    @Autowired
    private ICompanyService companyService;

    /**
     * @param id
     * @return com.hoshiibuy.common.rpc.Response
     * @description: 根据id查询部门信息
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "查询", notes = "查询入住公司信息")
    public Response findCompanyById(@PathVariable("id")  Long id) {
        //Neo4jRepository
        return Response.data(companyService.getById(id));
    }

    /**
     * @param
     * @return com.hoshiibuy.common.rpc.Response
     * @description: 根据名称查询
     */
    @GetMapping("/find/name")
    @ApiOperation(value = "查询", notes = "根据名称查询公司信息")
    public Response findCompanyByName(String name) {

        Wrapper wrapper = Wrappers.<Company>query().lambda().eq(Company::getName, name);

        return Response.data(companyService.getOne(wrapper));

    }

    /**
     * @param company
     * @return com.hoshiibuy.common.rpc.Response
     * @description: 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增",
            notes = "新增公司信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public Response saveCompany(@Valid Company company) {

        return Response.data(companyService.save(company));
    }

    /**
     * @param company
     * @return com.hoshiibuy.common.rpc.Response
     * @description: 修改
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改",
            notes = "修改公司信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public Response updateCompanyById(@Valid Company company) {
        return Response.data(companyService.updateById(company));

    }

}
